#ifndef BASE_PROPERTY_BINDER_H
#define BASE_PROPERTY_BINDER_H
#include <QObject>
#include <QList>
#include <QMetaProperty>
#include <memory.h>

class BasePropertyBinder:public QObject
{
    Q_OBJECT
    Q_PROPERTY(QObject *source READ source WRITE setSource NOTIFY sourceChanged FINAL)
    Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged FINAL)
public:
    BasePropertyBinder(QObject* parent = NULL);
    ~BasePropertyBinder();

    struct BindData{
        QObject* src;
        QMetaProperty srcProp;
        QObject* dst;
        QMetaProperty dstProp;
    };
    typedef QList<BindData> BindDataList;

    QObject *source() const;
    void setSource(QObject *newSource);

    QObject *target() const;
    void setTarget(QObject *newTarget);
    bool enabled() const;
    void setEnabled(bool newEnabled);

signals:
    void sourceChanged();
    void targetChanged();

    void enabledChanged();

protected:
    virtual BindDataList generateBindList() = 0;
    void update();
private:
    QObject* m_source = NULL;
    QObject* m_target = NULL;
    bool m_enabled = true;
    struct Data;
    std::unique_ptr<Data> data;
    Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged FINAL)
};


#endif
